﻿using System.Windows;
using System.Windows.Controls;

namespace NotificationAPI
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            #region Running State/Installer Checks
            // check to make sure the app is installed
            // if not, only show the installer
            if (App.Current.InstallState == InstallState.Installed)
            {
                InstallButton.Visibility = Visibility.Collapsed;
            }
            else
            {
                SimpleNotificationButton.Visibility = Visibility.Collapsed;
                CustomNotificationButton.Visibility = Visibility.Collapsed;
                return;
            }

            // check to make sure we're running OOB
            if (!App.Current.IsRunningOutOfBrowser)
            {
                WarningText.Visibility = Visibility.Visible;
                SimpleNotificationButton.Visibility = Visibility.Collapsed;
                CustomNotificationButton.Visibility = Visibility.Collapsed;
            }
            #endregion
        }

        private void InstallButton_Click(object sender, RoutedEventArgs e)
        {
            App.Current.Install();
        }

        private void SimpleNotificationButton_Click(object sender, RoutedEventArgs e)
        {
            NotificationWindow notify = new NotificationWindow();
            notify.Width = 329;
            notify.Height = 74;

            TextBlock tb = new TextBlock();
            tb.Text = "Sample notification";
            tb.FontSize = 24;

            notify.Content = tb;

            notify.Show(3000);
        }

        private void CustomNotificationButton_Click(object sender, RoutedEventArgs e)
        {
            // create the nofitication window API
            NotificationWindow notify = new NotificationWindow();
            notify.Height = 74;
            notify.Width = 329;

            // creating the content to be in the window
            CustomNotification custom = new CustomNotification();
            custom.Header = "Sample Header";
            custom.Text = "Hey this is a better looking notification!";
            custom.Width = notify.Width;
            custom.Height = notify.Height;

            // set the window content
            notify.Content = custom;

            // displaying the notification
            notify.Show(4000);
        }
    }
}
